package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {
    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;

    @Override
    public Integer addClues(ClueTrackRecordVo ClueTrackRecord) {
        TbClueTrackRecord tbClueTrackRecord = new TbClueTrackRecord();


        //封装数据
        // 1 线索ID
        tbClueTrackRecord.setClueId(ClueTrackRecord.getClueId());
        // 2 伪线索原因
        tbClueTrackRecord.setFalseReason(ClueTrackRecord.getFalseReason());
        // 3 创建人
        tbClueTrackRecord.setCreateBy(SecurityUtils.getUsername());
        // 4 意向学科
        tbClueTrackRecord.setSubject(ClueTrackRecord.getSubject());
        // 5 跟进记录
        tbClueTrackRecord.setRecord(ClueTrackRecord.getRecord());
        // 6 意向等级
        tbClueTrackRecord.setLevel(ClueTrackRecord.getLevel());
        // 7 下次跟进时间
        tbClueTrackRecord.setNextTime(ClueTrackRecord.getNextTime());
        // 8 创建时间
        tbClueTrackRecord.setCreateTime(DateUtils.getNowDate());
        // 9 跟进类型
        tbClueTrackRecord.setType(ClueTrackRecord.getType());

        Integer rows = tbClueTrackRecordMapper.addClues(tbClueTrackRecord);

        return rows;
    }

    @Override
    public TableDataInfo selectClueTrackById(Long clueId) {
        TableDataInfo dataInfo = new TableDataInfo();
        List<TbClueTrackRecord> tbClueTrackRecords = tbClueTrackRecordMapper.selectClueTrackById(clueId);
        if (tbClueTrackRecords.size() > 0) {
            dataInfo.setTotal(tbClueTrackRecords.size());
            dataInfo.setRows(tbClueTrackRecords);
            dataInfo.setMsg("查询成功");
            dataInfo.setCode(200);
            dataInfo.setParams(null);
            return dataInfo;
        }
        return null;
    }
}
